package org.third.integration.hibernate;



import javax.net.ssl.SSLContext;

import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class DbOracleTest extends DbTest {

	public static void main(String[] args) throws Exception {
		java.lang.System.setProperty("https.protocols", "SSLv3,TLSv1,TLSv1.1,TLSv1.2");
		java.lang.System.setProperty("jdk.tls.client.protocols","SSLv3,TLSv1,TLSv1.1,TLSv1.2");
		System.setProperty("javax.net.debug","ssl");
		System.setProperty("deployment.security.TLSv1.2","true");
//		URL url=new URL("https://www.baidu.com");
		
//		 javax.net.ssl.HttpsURLConnection urlConn = (javax.net.ssl.HttpsURLConnection) url.openConnection();
//		 urlConn.connect();
		new DbOracleTest().testDatabase();
	}

	public void testDatabase() {
		// int oracleId = CharacterSet.ZHS16GBK_CHARSET;
		// CharacterSet dbCharset = CharacterSet.make(oracleId);

		Connection conn = null;
		try {
			SSLContext context = SSLContext.getInstance("TLSv1.2");

        String    dbDriver="oracle.jdbc.driver.OracleDriver";
            Class.forName(dbDriver);
            //System.out.println("Connecting external "+dbType+" Database...");
            DriverManager.setLoginTimeout(10);
			// conn =
			// DriverManager.getConnection("jdbc:sqlserver://15.119.81.210\\SAML:1433;DatabaseName=idm_gongyo2",
			// "gongyo", "gongyo");
			String connectionUrl = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=16.155.195.45)(PORT=2484))(CONNECT_DATA=(SID=ORA12C)))";
//            String connectionUrl="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=shcssolindb01.hpeswlab.net)(PROTOCOL=tcps)(PORT=2484))(CONNECT_DATA=(SID=orcl)))";
			String user = "vincent";
			String password = "Admin111";
//
//			String connectionUrl = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=shcssolindb01.hpeswlab.net)(PROTOCOL=tcps)(PORT=2484))(CONNECT_DATA=(SID=orcl)))";
//			String user = "C##GONGYO1";
//			String password = "oracle";

			Properties props = new Properties();
			props.setProperty("user", user);
			props.setProperty("password", password);
			props.setProperty("javax.net.ssl.trustStore", "C:\\Program Files\\Java\\jdk1.8.0_171\\jre\\lib\\security\\cacerts");
			props.setProperty("javax.net.ssl.trustStorePassword", "changeit");
			props.setProperty("javax.net.ssl.trustStoreType", "jks");
//		    props.setProperty("oracle.net.ssl_cipher_suites","(SSL_RSA_WITH_3DES_EDE_CBC_SHA)");
			
			props.forEach((key, value)->{System.setProperty((String) key, (String)value);});
			
			conn = DriverManager.getConnection(connectionUrl, props);
//			conn.setSchema("C##YGONG");
//			conn.setCatalog("C##QIAsdsdNG");
			// printConnection(conn);

			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("select user from dual");
			printResultSet(rs);
			rs = stmt.executeQuery("select * from abstract_user");
			printResultSet(rs, "v$database");

			// stmt.execute(
			// "insert into aa_test(name) values(N'" + (test1) + "')");
			// ResultSet rs = stmt.executeQuery(
			// "select * from aa_test ");
			// while (rs.next()) {
			// System.out.println(rs.getString(1));
			// }

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
